package com.iris.live.services.data.repositories;

import com.iris.live.services.data.models.报价保险详细表Model;
import com.iris.live.services.data.models.报价保险详细表ModelPK;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by Xin on 7/8/2016.
 */
public interface 报价保险详细表Repository extends JpaRepository<报价保险详细表Model, 报价保险详细表ModelPK>, JpaSpecificationExecutor<报价保险详细表Model> {

    @Modifying
    @Query("delete from 报价保险详细表Model u where u.保险编号 = ?1 and u.险种 = ?2")
    int delBy保险编号And险种(int id, String type);

    @Modifying
    @Query("delete from 报价保险详细表Model u where u.保险编号 = ?1 and u.险种 <> ?2")
    int delBy保险编号And险种NotEquals(int id, String type);

    @Modifying
    @Query("delete from 报价保险详细表Model u where u.保险编号 = ?1 and u.第N年>?2 and (u.险种 <>'车船税'   and u.险种 <>'交强险')  ")
    int delBy保险编号AndYear(int id, int year);

    @Modifying
    @Query("delete from 报价保险详细表Model u where u.保险编号 = ?1 and u.第N年=?2 and (u.险种 <>'车船税'   and u.险种 <>'交强险')  ")
    int delBy保险编号AndYearT(int id, int year);

    @Query("select u from 报价保险详细表Model u where u.保险编号 = ?1 ")
    List<报价保险详细表Model> findBy保险编号(int id);

    @Query("select u from 报价保险详细表Model u where u.保险编号 = ?1  and u.险种<> '交强险' order by u.第N年 DESC")
    List<报价保险详细表Model> findByInsId(int id);

    @Query("select u from 报价保险详细表Model u where u.保险编号 = ?1  and u.险种='车船税' AND   u.第N年=1")
    报价保险详细表Model findCarByInsId(int id);

    @Query("select u from 报价保险详细表Model u where u.保险编号 = ?1  and   u.险种='交强险' AND   u.第N年=1")
    报价保险详细表Model findCarByInsIds(int id);


    @Modifying
    @Query("delete from 报价保险详细表Model u where u.保险编号 = ?1 and u.第N年 = ?2 and (u.险种 <>'车船税' and u.险种 <>'交强险')  ")
    int delBybianhaoAndNian(int id, int type);

    @Modifying
    @Query("update 报价保险详细表Model a set a.折后价=0 ,a.原价=0 where (a.险种='交强险' or a.险种='车船税') and a.第N年 >1 and a.保险编号 = ?1 ")
    int updateJqxSate(int id);

    @Query("select u from 报价保险详细表Model u where u.保险编号 = ?1 ")
    List<报价保险详细表Model> findInsurId(int id);

    @Modifying
    @Query("update 报价保险详细表Model a set a.手续费 = ?1 where  a.险种 = ?2 and  a.保险编号 = ?3 and  a.第N年 = ?4 ")
    int updateChange(String change,String Danger ,int id , int type);
}
